<?php
if (!defined('CURRENT_PATH')){
	die('Hacking attempt');
	}
	
if($_REQUEST['act']&&$_REQUEST['act']=='listframe'){
	$this->fid=intval($_REQUEST['fid']);
	$this->upload=$_REQUEST['upload'];	
    $this->display('management/slide_frame.html');
}else if($_REQUEST['act']&&$_REQUEST['act']=='list'){
	$fid=$_REQUEST['fid'];
	$this->fid=$fid;
	$this->upload=$_REQUEST['upload'];	
	$ip=spClass(img_player);
	$res=$ip->findAll($conditions=array('fid'=>$fid),$sort='show_order desc');
		if($fid==1){
			foreach($res as $id=>$v){
				$temp=null;
				$temp=(explode('||',$res[$id]['upload_discription']));
				$res[$id]['upload_discription']=$temp[0].'/'.$temp[1];				
		}
	}
	$this->res=$res;
	$this->display('management/pic_manage.html');
}else if($_REQUEST['act']&&$_REQUEST['act']=='add'){
	$this->fid=intval($_REQUEST['fid']);
	$this->upload=$_REQUEST['upload'];
	$this->display('management/silde_edit.html');	
}else if($_REQUEST['act']&&$_REQUEST['act']=='edit'){
	$id=intval($_REQUEST['id']);
	$ip=spClass(img_player);
	$res=$ip->find($conditions=array('id'=>$id));
	if($res['fid']==1){
		$temp=(explode('||',$res['upload_discription']));
		$res['upload_discription']=$temp[0];
		$res['temp1']=$temp[1];
		$res['temp2']=$temp[2];
	}
	$this->res=$res;
	$this->display('management/silde_edit.html');	
}else if($_REQUEST['act']&&$_REQUEST['act']=='del'){
	$id=intval($_REQUEST['id']);
	$ip=spClass(img_player);
	$fid=$ip->find($conditions=array('id'=>$id), $sort = null, $fields ='fid,upload_url');
	if(!in_array($fid['fid'],array())){//此处需要设定禁止
	$ip->delete($conditions=array('id'=>$id));
		header("Content-Type:text/html;charset=utf-8");
		echo'<script> alert("恭喜，图片删除成功！");parent.location.reload( );</script>';
		/*-delete image----*/
		@unlink (APP_PATH.$fid['upload_url']);
		@unlink (APP_PATH.preg_replace('/(\d+)\//U','\1/thumb/',$fid['upload_url']));	
	}else{
		header("Content-Type:text/html;charset=utf-8");
		echo'<script> alert("注意，此图片不能删除！");parent.location.reload( );</script>';		
	}
}else if($_REQUEST['act']&&$_REQUEST['act']=='saveAction'){	
	//dump($this->spArgs());
	$discription=$this->spArgs(temp1);
	$discription=isset($discription)?$this->spArgs(discription).'||'.$this->spArgs(temp1).'||'.$this->spArgs(temp2):$this->spArgs(discription);
	$ip=spClass(img_player);
/* save or update action ------------------------------------------------------------------*/	
if($this->spArgs(fid)!=null){
	$saveMapArr=array('fid'=>'fid','link_url'=>'upload_link','thumb'=>'upload_url','show_order'=>'show_order');
	$newrow=$this->DataToSave($saveMapArr,$this->spArgs(),array(id=>null,'upload_discription'=>$discription));
	$ip->create($newrow);
	header("Content-Type:text/html;charset=utf-8");
	echo'<script> alert("恭喜，图片新增成功,点击清空缓存可立刻在前台页面查看！");parent.location.reload( );</script>';
}else{
	$id=$this->spArgs(id);
	$saveMapArr=array('link_url'=>'upload_link','thumb'=>'upload_url','show_order'=>'show_order');
	$row=$this->DataToSave($saveMapArr,$this->spArgs(),array('upload_discription'=>$discription));
	$ip->update($conditions=array('id'=>$id),$row);
	header("Content-Type:text/html;charset=utf-8");
	echo'<script> alert("恭喜，图片修改成功！");parent.location.reload( );</script>';	

}
}else{
    $this->display('management/slide_home.html');	
}